package nc.gk.gkxm.config;

import lombok.extern.slf4j.Slf4j;
import nc.gk.gkxm.filter.JwtTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类，注册web层相关组件
 */
@Configuration
@Slf4j
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private JwtTokenInterceptor jwtTokenInterceptor;
    /**
     * 注册自定义拦截器
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry){
        log.info("开始注册自定义拦截器.....");
        registry.addInterceptor(jwtTokenInterceptor)  //添加要注册的自定义拦截器
                .addPathPatterns("/gkxm/api/**")  //要进行拦截的资源
                .excludePathPatterns("/gkxm/api/user/login"); //需要放行的资源
    }
}